﻿using System;
using System.Reflection;

namespace MathService
{
    public class Singleton<T> where T : class
    {
        private static class SingletonCreator
        {
            private static readonly T sf_Instance;

            public static T CreatorInstance { get { return sf_Instance; } }

            static SingletonCreator()
            {
                sf_Instance = (T)typeof(T).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, 
                    new Type[0], new ParameterModifier[0]).Invoke(null);
            }

        }

        public static T Instance { get { return SingletonCreator.CreatorInstance; } }

        protected Singleton() { }
    }


}
